// ObjectMenuDlg.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "ObjectMenuDlg.h"
#include "ObjectDialog.h"
#include "MeshImportFilter.h"
#include "VisualName.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CObjectMenuDlg dialog


CObjectMenuDlg::CObjectMenuDlg(	std::deque<VisualName> & v,CWnd* pParent /*=NULL*/)
	: CDialog(CObjectMenuDlg::IDD, pParent),visuals(v)
{
	//{{AFX_DATA_INIT(CObjectMenuDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CObjectMenuDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CObjectMenuDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CObjectMenuDlg, CDialog)
	//{{AFX_MSG_MAP(CObjectMenuDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnInsertar)
	ON_BN_CLICKED(IDC_BUTTON2, OnImportar)
	ON_BN_CLICKED(IDC_BUTTON4, OnModificar)
	ON_BN_CLICKED(IDC_BUTTON3, OnEliminar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CObjectMenuDlg message handlers

void CObjectMenuDlg::OnInsertar() 
{
	Object3D * child=new Object3D();
	CObjectDialog dlg(visuals,child);
	dlg.DoModal();
	object->addChild(child);
	OnOK();
}

void CObjectMenuDlg::OnImportar() 
{
	MeshImportFilter filter;
	Object3D * child;
	CFileDialog dlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"Ficheros 3DS|*.3ds||");
	dlg.m_ofn.lpstrInitialDir=NULL;
	if (dlg.DoModal()==IDOK){
		child=new Object3D();
		filter(child,(char *)(LPCSTR)dlg.GetPathName());
		object->addChild(child);
	}	
	OnOK();
}

void CObjectMenuDlg::OnModificar() 
{
	CObjectDialog dlg(visuals,object);
	dlg.DoModal();
	OnOK();
	
}

void CObjectMenuDlg::OnEliminar() 
{
	unsigned child;
	Object3D * parent=root->findParent(object->getID(),child);
	parent->removeChild(child);
	OnOK();
}
